poshidprobs_user = 1./(1 + exp(-rate_matrix_user*vishid_user - repmat(hidbiases_user,num_users,1)));    
negdata_user = poshidprobs_user*vishid_user' + repmat(visbiases_user, num_users,1);
  
finalresult_user = zeros(num_users, num_items);
template = [1 2 3 4 5];
for m=1:num_users
    reshap = reshape(negdata_user(m,:),5, num_items);
    reshap = exp(reshap - repmat(max(reshap), 5, 1));
    reshap = reshap./repmat(sum(reshap), 5, 1);
    finalresult_user(m,:) = template*reshap;
end

finalresult_user = finalresult_user.*test_template;
mae_user = sum(sum(abs(finalresult_user-test_real_matrix)))/test_size;
%fprintf(1, '               user: %4i   MAE %6f \n', epoch, mae);


poshidprobs_item = 1./(1 + exp(-rate_matrix_item*vishid_item - repmat(hidbiases_item,num_items,1)));    
negdata_item = poshidprobs_item*vishid_item' + repmat(visbiases_item, num_items,1);
  
finalresult_item = zeros(num_items, num_users);
template = [1 2 3 4 5];
for m=1:num_items
    reshap = reshape(negdata_item(m,:),5, num_users);
    reshap = exp(reshap - repmat(max(reshap), 5, 1));
    reshap = reshap./repmat(sum(reshap), 5, 1);
    finalresult_item(m,:) = template*reshap;
end

finalresult_item = finalresult_item'.*test_template;
mae_item = sum(sum(abs(finalresult_item-test_real_matrix)))/test_size;
%fprintf(1, '               item: %4i   MAE %6f \n', epoch, mae);


finalresult = (finalresult_user+finalresult_item)/2;



mae = sum(sum(abs(finalresult-test_real_matrix)))/test_size;

    
fprintf(1, 'epoch %4i   MAE %6f    MAE_user %6f    MAE_item %6f  :%6f  %6f  %6f\n', epoch, mae, mae_user, mae_item, mae_user-mae, mae_item-mae, mae_item-mae_user);

